package com.sicheng.hello.service.impl;

import com.sicheng.hello.service.AsyncService;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.Future;

/**
 * @author zsc
 * @version 1.0
 * @date 2021/10/2 23:01
 */
@Service
public class AsyncServiceImpl implements AsyncService {


    @Resource
    private ThreadPoolTaskExecutor taskExecutor;


    public Integer exec(Integer millis) {

         taskExecutor.submit(() -> {


        });

        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return millis;
    }

    @Override
    public Future<Integer> executeAsyncWithFuture(Integer millis) {
        return AsyncResult.forValue(exec(millis));
    }
}
